package com.lzx.indicatordemo.demo;

import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.framework.view.indicator.GodIndicator;
import com.framework.view.indicator.PointIndicatorAdapter;
import com.framework.view.indicator.configs.GlobalConfig;
import com.framework.view.indicator.indicators.configs.PointIndicatorConfig;
import com.framework.view.indicator.model.StrokeType;
import com.lzx.indicatordemo.Constants;
import com.lzx.indicatordemo.ExamplePagerAdapter;
import com.lzx.indicatordemo.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

import static com.lzx.indicatordemo.Constants.CHANNELS;

/**
 * description
 *
 * @author liangzx
 * @version 1.0
 * @time 2019-12-23 10:53
 **/
public class PointIndicatorDemoActivity extends AppCompatActivity implements View.OnClickListener {

    private ArrayList<String> mDataList = new ArrayList<>(Arrays.asList(CHANNELS));
    private ViewPager mViewPager;
    private ExamplePagerAdapter mExamplePagerAdapter = new ExamplePagerAdapter(mDataList);

    private PointIndicatorAdapter mAdapter1, mAdapter2, mAdapter3, mAdapter4, mAdapter5, mAdapter6, mAdapter7, mAdapter8;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.point_indicator_demo_activity);

        mViewPager = findViewById(R.id.vp);
        mViewPager.setAdapter(mExamplePagerAdapter);
        findViewById(R.id.update_btn).setOnClickListener(this);
        init1();
        init2();
        init3();
        init4();
        init5();
        init6();
        init7();
        init8();
    }

    @Override
    public void onClick(View view) {
        if (R.id.update_btn == view.getId()) {
            int count = new Random().nextInt(CHANNELS.length) + 1;
            Log.e(PointIndicatorDemoActivity.class.getName(), "count:" + count);
            mDataList.clear();
            for (int i = 0; i < count; i++) {
                mDataList.add(CHANNELS[i]);
            }
            mExamplePagerAdapter.notifyDataSetChanged();
            mAdapter1.notifyDataSetChanged();
            mAdapter2.notifyDataSetChanged();
            mAdapter3.notifyDataSetChanged();
            mAdapter4.notifyDataSetChanged();
            mAdapter5.notifyDataSetChanged();
            mAdapter6.notifyDataSetChanged();
            mAdapter7.notifyDataSetChanged();
            mAdapter8.notifyDataSetChanged();
        }
    }

    private void init1() {
        GodIndicator godIndicator = findViewById(R.id.g1);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(mAdapter1 = new PointIndicatorAdapter() {

            @Override
            protected void bindGlobalConfig(GlobalConfig config) {
                config.setFollowFinger(false);
            }

            @Override
            protected PointIndicatorConfig bindIndicatorConfig() {
                return PointIndicatorConfig.factory()
                        .setNormalColor(Constants.randomIndicatorColor())
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setCircleType(20, 30)
                        .setPanding(30);
            }
        });
        mAdapter1.bindViewPager(mViewPager);
    }

    private void init2() {
        GodIndicator godIndicator = findViewById(R.id.g2);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(mAdapter2 = new PointIndicatorAdapter() {

//            @Override
//            public int getCount() {
//                return mDataList.size();
//            }

            @Override
            protected PointIndicatorConfig bindIndicatorConfig() {
                return PointIndicatorConfig.factory()
                        .setNormalColor(Constants.randomIndicatorColor())
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setRectType(20, 40)
                        .setPanding(25);
            }
        });
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mAdapter2.bindViewPager(mViewPager);
            }
        }, 3000);
    }

    private void init3() {
        GodIndicator godIndicator = findViewById(R.id.g3);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(mAdapter3 = new PointIndicatorAdapter(mViewPager) {

//            @Override
//            public int getCount() {
//                return mDataList.size();
//            }

            @Override
            protected PointIndicatorConfig bindIndicatorConfig() {
                return PointIndicatorConfig.factory()
                        .setNormalColor(Constants.randomIndicatorColor())
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setRoundRectType(20, 30)
                        .setRoundRadius(6)
                        .setPanding(20);
            }

        });
    }

    private void init4() {
        GodIndicator godIndicator = findViewById(R.id.g4);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(mAdapter4 = new PointIndicatorAdapter(mViewPager) {

            @Override
            public int getCount() {
                return mDataList.size();
            }

            @Override
            protected PointIndicatorConfig bindIndicatorConfig() {
                return PointIndicatorConfig.factory()
                        .setNormalColor(Constants.randomIndicatorColor())
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setCircleType(40, 40)
                        .setRoundRadius(6)
                        .setStroke(StrokeType.JUST_NORMAL, 5)
                        .setPanding(20);
            }

        });
    }

    private void init5() {
        GodIndicator godIndicator = findViewById(R.id.g5);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(mAdapter5 = new PointIndicatorAdapter(mViewPager) {

            @Override
            public int getCount() {
                return mDataList.size();
            }

            @Override
            protected PointIndicatorConfig bindIndicatorConfig() {
                return PointIndicatorConfig.factory()
                        .setNormalColor(Constants.randomIndicatorColor())
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setCircleType(40, 40)
                        .setRoundRadius(6)
                        .setStroke(StrokeType.JUST_SELECTED, 5)
                        .setPanding(20);
//                return PointIndicatorConfig.factory()
//                        .setNormalColor(Constants.randomIndicatorColor())
//                        .setSelectedColor(Constants.randomIndicatorColor())
//                        .setRectType(40, 40)
//                        .setRoundRadius(6)
//                        .setStroke(StrokeType.JUST_NORMAL, 5)
//                        .setPanding(20);
            }

        });
    }

    private void init6() {
        GodIndicator godIndicator = findViewById(R.id.g6);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(mAdapter6 = new PointIndicatorAdapter(mViewPager) {

            @Override
            public int getCount() {
                return mDataList.size();
            }

            @Override
            protected PointIndicatorConfig bindIndicatorConfig() {
                return PointIndicatorConfig.factory()
                        .setNormalColor(Constants.randomIndicatorColor())
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setRoundRectType(40, 40)
                        .setRoundRadius(6)
                        .setStroke(StrokeType.JUST_NORMAL, 10)
                        .setPanding(20);
            }

        });
    }

    private void init7() {
        GodIndicator godIndicator = findViewById(R.id.g7);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(mAdapter7 = new PointIndicatorAdapter(mViewPager) {

            @Override
            public int getCount() {
                return mDataList.size();
            }

            @Override
            protected PointIndicatorConfig bindIndicatorConfig() {
                return PointIndicatorConfig.factory()
                        .setNormalColor(Constants.randomIndicatorColor())
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setRectType(30, 40)
                        .setRoundRadius(6)
                        .setStroke(StrokeType.JUST_SELECTED, 10)
                        .setPanding(20);
            }

        });
    }

    private void init8() {
        GodIndicator godIndicator = findViewById(R.id.g8);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(mAdapter8 = new PointIndicatorAdapter(mViewPager) {

            @Override
            public int getCount() {
                return mDataList.size();
            }

            @Override
            protected PointIndicatorConfig bindIndicatorConfig() {
                return PointIndicatorConfig.factory()
                        .setNormalColor(Constants.randomIndicatorColor())
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setRectType(20, 40)
                        .setRoundRadius(6)
                        .setStroke(StrokeType.ALL, 10)
                        .setPanding(20);
            }

        });
    }

}
